<template>
  <view class="message-details-block" v-if="data">
    <view class="time-text">
      <text>{{ data.createTime | formatDate("yyyy年MM月dd日 hh:mm") }}</text>
    </view>
    <view class="container">
      <image class="avatar" :src="icon"></image>
      <view class="message-content">
        用户“
        <text class="active" @click="handleGoUser(data.sendUser.userId)">
          {{ data.sendUser.userName }}
        </text>
        ” {{ data.tips }}
        <text class="active" @click="handleGodetail(data.type)">
          {{ data.content }}
        </text>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name: "message-details-block",
    props: {
      data: {
        default: () => {
          return {
            type: 0
          };
        },
        type: Object,
      },
      type: {
        type: Number | String,
        default: 0
      }
    },
    data() {
      return {};
    },
    computed: {
      icon() {
        return getApp().globalData.message_config[this.type].imageLink;
      }
    },
    methods: {
      handleGoUser(uid) {
        if (this.data.type == 0) {
          return;
        }
        uni.navigateTo({
          url: `/pages/my/userInfo/userInfo?id=${uid}`,
        });
      },
      handleGodetail(type) {
        if (type == 0) {
          return;
        }
        let url = "";
        switch (type) {
          case "1":
          case "2":
            url = '/pages/community/article-details/article-details';
            break;
          case "4":
          case "5":
            url = '/pages/used/product-details/product-details';
            break;
          case "3":
            url = '/pages/community/article-details/article-details';
            break;
          case "6":
            url = '/pages/used/product-details/product-details';
            break;
          case "7":
            if (this.data.operObj.type == 0) {
              url = '/pages/community/article-details/article-details';
            } else {
              url = '/pages/used/product-details/product-details';
            }
            break;
          default:
            break;
        }
        uni.navigateTo({
          url: url + `?id=${this.data.operObj.commonId}`,
        });
      },
    },
  };
</script>

<style lang="scss" scoped>
  .message-details-block {
    padding: 0 32rpx;
    padding-bottom: 16rpx;

    .time-text {
      text-align: center;
      color: #cccccc;
      font-size: 26rpx;
      padding: 32rpx;
    }

    .container {
      display: flex;
      align-items: center;
      justify-content: space-between;

      .avatar {
        width: 88rpx;
        height: 88rpx;
        border-radius: 50%;
        min-width: 88rpx;
        min-height: 88rpx;
      }

      .message-content {
        font-size: 28rpx;
        background-color: #eef2f4;
        margin-left: 16rpx;
        padding: 16rpx;
        width: 100%;

        .active {
          color: #3fd3d1;
        }
      }
    }
  }
</style>
